package com.tool.stock.manager;

import com.tool.stock.entity.PriceBO;
import com.tool.stock.store.FiveAverageStore;

/**
 * 价格处理类.
 */
public class PriceManager {

    /**
     * 将股价列表组装成对象数组.
     * 每4个为一组
     *
     * @param price 股价数组
     * @return 组装好的对象数组
     */
    public PriceBO[] calculatePrice(int[] price) {
        int priceSize = price.length/4;
        PriceBO[] priceArr = new PriceBO[priceSize];

        int step = 4;
        for (int i = 0; i < priceSize; i++) {
            int[] singlePrice = new int[step];
            System.arraycopy(price, i * step, singlePrice, 0, step);
            PriceBO priceBO = new PriceBO(singlePrice);
            float average = FiveAverageStore.getInstance().addPrice(priceBO.getClosingPrice()).average();
            priceBO.setFiveAverage(average);
            priceArr[i] = priceBO;
        }

        return priceArr;
    }
}
